<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@ page import="java.lang.Runnable"%>
<%@ page import="java.lang.Thread"%>
<%@ page import="java.io.*"%>
<%!
int index=0;
String usbandvalue="";
%>

<%!
class BurnRunnable implements Runnable{
private int usbnumber;
private int nodeid;
private String filename;
public int exitValue;

// static int index=0;
// static String usbandvalue="";
//int index=0;
//String usbandvalue="";
public BurnRunnable(int nodeid,int usbnumber,String filename){
this.nodeid=nodeid;
this.usbnumber=usbnumber;
this.filename=filename;
}
public  void run(){
String cmd="tos-bsl --telosb -c /dev/ttyUSB"+this.usbnumber+" -r -e -I -p /home/wyg/lly/downfile/"+this.filename;
try{
Process process = java.lang.Runtime.getRuntime().exec(cmd);
this.exitValue=process.waitFor();
//this.index++;
///this.usbandvalue+=this.nodeid+","+this.exitValue+",";
usbandvalue+=this.nodeid+","+this.exitValue+",";
index++;
//	BurnRunnable.index++;
//	BurnRunnable.usbandvalue+=this.nodeid+","+this.exitValue+",";
//out.println(usb+","+exitValue+",");
}catch(Exception ee){}
}
}
%>
<%
String success="Success!";
String warning="Error!\nCannot connect to Nodes!";
request.setCharacterEncoding("GBK");
String nodestr = request.getParameter("showid");
String[] strarray=nodestr.split(","); 
String cmd="";
Cookie[] cookies = request.getCookies();
//About State
StringBuilder infoMsg=new StringBuilder();  
StringBuilder errorMsg=new StringBuilder();  
String line=null;  

String filename="";
int usbnum[]={53,77,74,76,49,51,52,78,50,75,35,13,14,36,37,38,10,11,12,34,65,42,43,41,67,66,64,40,39,68,30,29,9,8,6,31,5,32,33,7,25,0,1,28,4,3,24,2,27,26,46,44,69,72,47,45,71,73,48,70,22,23,20,21,60,61,59,19,62,63,18,17,56,55,16,57,58,54};
for(int i=0;i<cookies.length;i++){
if(cookies[i].getName().equals("filename"))
{	
filename = cookies[i].getValue();
}
}
for(int i=0;i<strarray.length;i++)//zhe li yong string de length
{
int nodeid = Integer.parseInt(strarray[i]);
int usbnumber = usbnum[nodeid];
new Thread(new BurnRunnable(nodeid,usbnumber,filename)).start();;
//out.println(usb+","+br.exitValue+",");
//out.println(usbandvalue);
}
//out.println("xxx");
//out.println(index+" "+strarray.length);
//out.println("xxxx");
while(index<(strarray.length)){
//System.out.println("aaa"+index);
boolean flag=true;
if(flag){
out.println("");
flag=false;
}
}
out.println(usbandvalue);
index=0;
usbandvalue="";
/*

for(int i=0;i<strarray.length;i++)//zhe li yong string de length
{
int usb = Integer.parseInt(strarray[i]);
int usbnumber = usbnum[usb];
cmd="tos-bsl --telosb -c /dev/ttyUSB"+usbnumber+" -r -e -I -p /home/wyg/lly/downfile/"+filename;
Process process = java.lang.Runtime.getRuntime().exec(cmd);
int exitValue=process.waitFor();
out.println(usb+","+exitValue+",");
}
*/
%>

